﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO.Model;
using DAO.Bussiness.Repository;
using System.Collections;


namespace Restaurante
{
    public partial class sectores : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
                

        protected void btnAceptar_Click(object sender, EventArgs e)
        {
            SectorRepository sr = new SectorRepository();
            Sector sec = new Sector();
            try
            {
                sec.Descripcion = txbDescripcion.Text;
            }
            catch
            {
            }
            finally
            {
                sr.Add(sec);
                sr.Save();
                CleanControl(this.Controls);
                Response.Redirect("sectores.aspx");
            }
        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            Response.Redirect("home.aspx");
        }
        public void CleanControl(ControlCollection controles)
        {
            foreach (Control control in controles)
            {
                if (control is TextBox)
                    ((TextBox)control).Text = string.Empty;
                else if (control.HasControls())
                    //Esta linea detécta un Control que contenga otros Controles
                    //Así ningún control se quedará sin ser limpiado.
                    CleanControl(control.Controls);
            }
        }          
    }
}